using System;
using System.Web.UI.WebControls;
using OpenNetCommerce.Localization.resources;

namespace OpenNetCommerce.Localization
{

	public static class LocalizationUtility
	{

		#region Methods

		#region Public

		/// <summary>
		/// Adds the hover HTML.
		/// </summary>
		/// <param name="hyperlink">The hyperlink.</param>
		/// <param name="html">The HTML.</param>
		public static void AddHoverHtml(HyperLink hyperlink, string html)
		{
			hyperlink.Attributes.Add("onmouseover", string.Format(Overlib.SIMPLE, html));
			hyperlink.Attributes.Add("onmouseout", Overlib.MOUSEOUT);
		}


		/// <summary>
		/// Adds the image alternate text.
		/// </summary>
		/// <param name="image">The image.</param>
		public static void AddImageAlternateText(System.Web.UI.WebControls.Image image)
		{
			image.AlternateText = labels.ResourceManager.GetString(image.ID) ?? String.Empty;
		}

		/// <summary>
		/// Gets the text from the labels resource.
		/// </summary>
		/// <param name="name">The name.</param>
		/// <returns></returns>
		public static string GetText(string name)
		{
			string s = labels.ResourceManager.GetString(name);
			if (String.IsNullOrEmpty(s))
				return String.Empty;
			return MacroSystem.Replace(s);
		}

		/// <summary>
		/// Gets the help text.
		/// </summary>
		/// <param name="name">The name.</param>
		/// <returns></returns>
		public static string GetHelpText(string name)
		{
			string s = help.ResourceManager.GetString(name);
			if (String.IsNullOrEmpty(s))
				return String.Empty;
			return MacroSystem.Replace(s);
		}

		/// <summary>
		/// Gets the critical message text.
		/// </summary>
		/// <param name="message">The message.</param>
		/// <returns></returns>
		public static string GetCriticalMessageText(string message)
		{
			return string.Format(GetText("lblCriticalError"), message);
		}

		/// <summary>
		/// Gets the payment provider error text.
		/// </summary>
		/// <param name="message">The message.</param>
		/// <returns></returns>
		public static string GetPaymentProviderErrorText(string message)
		{
			return string.Format(GetText("lblPaymentProviderError"), message);
		}

		#endregion

		#endregion


		//#region Macros processing properties and methods

		//private const string MACRO_ProductName = "$(ProductName)";

		//public static readonly string[] PredefinedMacros = { MACRO_ProductName };

		//public static string ReplaceMacros(string text)
		//{
		//   if (String.IsNullOrEmpty(text))
		//      throw new ArgumentNullException("text");

		//   foreach (string macro in PredefinedMacros) {
		//      switch (macro) {
		//         case MACRO_ProductName:
		//            text.Replace(macro, MettleSystems.dashCommerce.Core.WebApplicationBase.ProductName);
		//            break;
		//      }
		//   }
		//   return text;
		//}

		//#endregion
	}
}
